home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / linux-bo / dless-li / root.no / etc / rc.d / rc.bootp < prev    next >
Text File  |  1995-04-28  |  6KB  |  226 lines

  1. ####!/bin/sh
  2. # Written to simply set the IP stuff up from the
  3. # bootpc data.
  4. # Last updated : Thu Aug 18 17:52:14 1994
  5. #  Jon Peatfield
  6. #
  7. # with modifications as suggested by Austin Donnelly, Chris Hall and
  8. # Donal K Fellows.
  9. #
  10. # Version 0.31
  11. #set -x
  12.  
  13. /sbin/mount /proc /proc -t proc
  14. ## YOU MAY NEED TO EDIT THESE FOR DIFFERENT DISTRIBUTIONS
  15. # Location of the bootpc program
  16. BOOTPC=/sbin/bootpc
  17. # location of ifconfig
  18. IFCONFIG=/sbin/ifconfig
  19. # location of route
  20. ROUTE=/sbin/route
  21. # location of hostname binary
  22. BINHOST=/bin/hostname
  23.  
  24. ## Details of bootp to perform
  25. # What device to do the bootp on
  26. DEV=eth0
  27. # What address to send bootp request to (broadcast by default)
  28. #ASKSERVER="163.178.101.5"
  29. ASKSERVER="255.255.255.255"
  30.  
  31. ## Shouldn't change location, but...
  32. # The location of the resolver config file
  33. RCONF=/etc/resolv.conf
  34. # location of the hosts file
  35. EHOSTS=/etc/hosts
  36.  
  37. # For testing purposes
  38. # BOOTPC=./bootpc
  39. # IFCONFIG=/bin/echo
  40. # ROUTE=/bin/echo
  41. # BINHOST=/bin/echo
  42. # RCONF=/tmp/resolv.conf
  43. # EHOSTS=/tmp/hosts
  44. # ASKSERVER="131.111.16.31"
  45. # set -x
  46.  
  47. ## Start of the functions
  48. # Stick the nameserver lines in the resolver file.
  49. setservers() {
  50. # Insert the DNS servers themselves
  51.   for i in $1
  52.   do
  53.     echo "nameserver $i" >> ${RCONF}
  54.   done
  55. }
  56.  
  57. # A function for setting the DNS stuff if we have all the info
  58. setresolv() {
  59.   [ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.old
  60. # Insert provided domain
  61.   echo "domain $1" > ${RCONF}
  62.   setservers "$2"
  63. }
  64.  
  65. # A function for setting the DNS stuff if we don't know out domainname
  66. fakeresolv() {
  67.   [ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.fake
  68. # This means nothing, but provides a domain line (some(old) revolvers
  69. #  break if there isn't one present.)
  70.   echo "domain ." > ${RCONF}
  71.   setservers "$1"
  72. }
  73.  
  74. # And putting the original back if it exists
  75. unfakeresolv() {
  76.   [ -f ${RCONF}.fake ] && mv -f ${RCONF}.fake ${RCONF}
  77. }
  78.  
  79. # update the DNSSERVERS but not the domainname, in case of
  80. # reverse lookup failure.
  81. updateresolv() {
  82.   [ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.old
  83. # Copy over the domainname from the old file
  84.   grep 'domain' ${RCONF}.old > ${RCONF}
  85.   setservers "$1"
  86. }
  87. ## End of the functions
  88.  
  89. ## Start of the actual work
  90. # Mount /proc filesystem
  91. # Bring up minimal networking
  92. echo "Minimal networking...."
  93. ${IFCONFIG} ${DEV} up
  94. ${ROUTE} add default dev ${DEV}
  95. # Perform the bootp  --  doesn't return unless it gets an answer
  96. echo "Calling bootp...."
  97. #sh eval `${BOOTPC} --dev ${DEV} --server ${ASKSERVER}`
  98. eval `${BOOTPC}`
  99. # Take down networking
  100. echo "Undefining network..."
  101. ${ROUTE} del default
  102. ${IFCONFIG} ${DEV} down
  103.  
  104. # Only SERVER and IPADDR are guarenteed by the bootp (assuming
  105. # It works), so check the rest.
  106.  
  107. # Start the loopback interface etc
  108. echo "Loopback definition...."
  109. ${IFCONFIG} lo 127.0.0.1
  110. ${ROUTE} add -net 127.0.0.0
  111.  
  112. # Setup of IP stuff needs doing first
  113. #
  114. echo "Displaying how interface will be configured...."
  115. echo "---------------------------------"
  116. echo "HOSTNAME=${HOSTNAME}"
  117. echo "IPADDR=${IPADDR}"
  118. echo "NETWORK=${NETWORK}"
  119. echo "BROADCAST=${BROADCAST}"
  120. echo "NETMASK=${NETMASK}"
  121. echo "GATEWAYS=${GATEWAYS}"
  122. echo "DNS servers=${DNSSRVS}"
  123. echo "Host domain=${HOSTDOMAIN}"
  124. echo "---------------------------------"
  125.  
  126. echo "Defining interface...."
  127. if [ -z "${NETMASK}" ] ; then
  128. # No netmask info, all this is guessed from the IP number
  129. # If this is wrong for your network FIX the bootpd to know
  130. # what it should send in the RFC1497 cookie!  11/02/94 JSP
  131. #
  132.   ${IFCONFIG} ${DEV} up ${IPADDR} broadcast ${BROADCAST}
  133.   ${ROUTE} -n add -net ${NETWORK} dev ${DEV}
  134. else
  135. # We will have NETMASK, BROADCAST, and NETWORK defined 
  136.   ${IFCONFIG} ${DEV} up ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
  137.   ${ROUTE} -n add -net ${NETWORK} dev ${DEV}
  138. fi
  139.  
  140. # Gateways need IP to be able to add the (primary) route.
  141. #
  142. echo "Defining gateways...."
  143. if [ -z "${GATEWAYS}" ] ; then
  144. # No gateways defined
  145.   echo "No IP gateways defined in rc.bootp setup"
  146. else
  147. # First one listed is supposedly our best, so only use it.
  148.   set - ${GATEWAYS}
  149.   ${ROUTE} add default gw ${1}
  150. fi
  151.  
  152. # May need Gateways if the DNS servers are on the other side of the
  153. # gateways, this needs IP to be up.
  154. #
  155. # Can we set up DNS?
  156. echo "Defining DNS....."
  157. if [ ! -z "${DNSSRVS}" ]; then
  158.   if [ ! -z "${DOMAIN}" ]; then
  159.     setresolv "${DOMAIN}" "${DNSSRVS}" 
  160.   else
  161. # At least we have DNS, so use reverse lookup to get DOMAIN
  162. # Fake the resolver setup to do the reverse lookup.
  163.     fakeresolv "${DNSSRVS}" 
  164.     eval `${BOOTPC} --in2host ${IPADDR}`
  165.     unfakeresolv
  166.     if [ ! -z "${HOSTDOMAIN}" ]; then
  167. # Got a domain, so use it
  168.       setresolv "${HOSTDOMAIN}" "${DNSSRVS}"
  169.     else
  170. # We have DNSSRVS but no DOMAIN, and reverse lookup failed
  171. # If the resolver file is there use it's domainname
  172.       if [ -f ${RCONF} ] ; then
  173.     echo "Using old value from /etc/resolve.conf for DOMAIN"
  174.     updateresolv "${DNSSRVS}"
  175.       else
  176.         echo "No BOOTP DOMAIN supplied"
  177.     echo "  reverse lookup failed"
  178.     echo "  and no existing resolver file"
  179.     echo "=>   resolver setup failed"
  180.       fi
  181.     fi
  182.   fi
  183. else
  184.   echo "No DNSSRVS supplied, resolver setup not possible"
  185. fi
  186.  
  187. # May need DNS lookups if not provided by bootpd
  188. #
  189. # Set the hostname from what we got via bootp or reverse lookup
  190. if [ ! -z "${HOSTNAME}" ]; then
  191.   ${BINHOST} "${HOSTNAME}"
  192.   cat ${HOSTNAME} >> /etc/HOSTNAME
  193.   echo "127.0.0.1    loopback ${HOSTNAME} localhost">${EHOSTS}
  194. else
  195.   if [ -z "${DONEIN2HOST}" ] ; then
  196.     eval `${BOOTPC} --in2host ${IPADDR}`
  197.   fi
  198.   if [ ! -z "${HOSTLEAF}" ]; then
  199.     ${BINHOST} "${HOSTLEAF}"
  200.     echo "127.0.0.1    loopback ${HOSTLEAF} ${HOSTFULL} localhost">${EHOSTS}
  201.   fi
  202. fi
  203.  
  204. # None of this is relevant to IP startup but may be handy for some people
  205. #
  206. # Tell them about other info we got back, but don't use it
  207. # 'cos I'm too lazy to write code for this...
  208. #
  209. # Print out a value if present  JSP
  210. printifhere() {
  211.   [ ! -z "$2" ] && echo "$1 = $2"
  212. }
  213.  
  214. printifhere    TIMESRVS    "${TIMESRVS}"
  215. printifhere    IEN116SRVS    "${IEN116SRVS}"
  216. printifhere    LOGSRVS        "${LOGSRVS}"
  217. printifhere    QODSRVS        "${QODSRVS}"
  218. printifhere    LPRSRVS        "${LPRSRVS}"
  219. printifhere    IMPRESSSRVS    "${IMPRESSSRVS}"
  220. printifhere    RLPSRVS        "${RLPSRVS}"
  221. printifhere    SWAPSRVR    "${SWAPSRVR}"
  222.  
  223. #
  224. #
  225. ## End of the mail work
  226.